<template lang="">
  <div>
    <div class="ser_div">
      <el-row>
        <el-col :span="4">
          <!-- <el-button
            @click="model_number_click"
            style="margin-left: 15px; background: #1890ff; color: aliceblue"
          >
            搜索</el-button
          > -->
          <el-button
            @click="add_model"
            style="background: #1890ff; color: aliceblue"
            >新增型号</el-button
          >
        </el-col>
      </el-row>
    </div>
    <el-table :data="ModelList" stripe style="width: 100%" border>
      <el-table-column prop="modelname" label="名称"> </el-table-column>
      <el-table-column label="操作" width="250" fixed="right">
        <template slot-scope="scope">
          <el-button @click="push_ziduan(scope.row)" type="text"
            >字段列表</el-button
          >
          <el-button
            @click="set_moxing(scope.row)"
            type="text"
            style="margin-left: 10px"
            >修改</el-button
          >
          <el-popconfirm
            confirm-button-text="确定"
            cancel-button-text="取消"
            icon="el-icon-info"
            icon-color="red"
            title="确定删除该模型吗？"
            @confirm="del_moxing(scope.row)"
          >
            <el-button slot="reference" type="text" style="margin-left: 10px"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      :title="title"
      :visible.sync="isProduct"
      width="30%"
      :close-on-click-modal="false"
      @close="close_diolog"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="模型名称 " prop="modelname">
          <el-input v-model="ruleForm.modelname" placeholder='请输入模型名称' style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="表名 " prop="tablename">
          <el-input v-model="ruleForm.tablename" placeholder='请输入表名'  style="width: 50%"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isProduct = false">取 消</el-button>
        <el-button type="primary" @click="add_Model('ruleForm')"
          >确定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getModelList, addModel } from "@/api/product/index";
export default {
  data() {
    return {
      isProduct: true,
      ModelList: [],
      title:'',
      ruleForm: {
        modelname: "",
        tablename: "",
      },
      rules: {
        modelname: [
          { required: true, message: "请输入模型名称", trigger: "blur" },
        ],
        tablename: [
          { required: true, message: "请输入表名", trigger: "blur" },
        ]
      },
    };
  },
  mounted() {
    this.get_ModelList();
  },
  methods: {
    get_ModelList() {
      let obj = {
        is_dropdown: 1,
      };
      getModelList(obj).then((res) => {
        if (res.code == 200) {
          this.ModelList = res.data;
        }
      });
    },
    push_ziduan(row) {
      this.$router.push({
        name: "ziduanlist",
        path: "/ziduanlist",
        query: {
          data: row.modelid,
        },
      });
    },
    set_moxing() {},
    del_moxing() {},
    add_model() {
      this.title='添加模型'
      this.isProduct=true
    },
    close_diolog(){
      
    },
    add_Model(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          addModel().then((res) => {
            if (res.code == 200) {
              this.isProduct = false;
              this.$message.success("提交成功");
              this.get_ModelList();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
     
    },
  },
};
</script>
<style lang=""></style>
